
<!DOCTYPE HTML>
<html lang="zh-hans" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>CodePush 热更新配置及使用 · 《前端学习笔记》</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        <meta name="author" content="XiaoChen">
        
        
    
    <link rel="stylesheet" href="../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-expandable-chapters/expandable-chapters.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-code/plugin.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-pageview-count/plugin.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-chapter-fold/chapter-fold.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-expandable-chapters-small/expandable-chapters-small.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-tbfed-pagefooter/footer.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-ancre-navigation/style/plugin.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="已有Android工程 集成React Native.html" />
    
    
    <link rel="prev" href="../Android/Android UI美化之 shape的使用及其属性总结.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="输入并搜索" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        <li class="header">前言</li>
        
        
    
        <li class="chapter " data-level="1.1" data-path="../">
            
                <a href="../">
            
                    
                    简介
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">Android</li>
        
        
    
        <li class="chapter " data-level="2.1" data-path="../Android/Android 多包名打包应用.html">
            
                <a href="../Android/Android 多包名打包应用.html">
            
                    
                    Android 多包名打包应用
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.2" data-path="../Android/Android UI美化之 shape的使用及其属性总结.html">
            
                <a href="../Android/Android UI美化之 shape的使用及其属性总结.html">
            
                    
                    Android UI美化之 shape的使用及其属性总结
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">ReactNative</li>
        
        
    
        <li class="chapter active" data-level="3.1" data-path="CodePush 热更新配置及使用.html">
            
                <a href="CodePush 热更新配置及使用.html">
            
                    
                    CodePush 热更新配置及使用
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.2" data-path="已有Android工程 集成React Native.html">
            
                <a href="已有Android工程 集成React Native.html">
            
                    
                    已有Android工程 集成React Native
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">Egret</li>
        
        
    
        <li class="chapter " data-level="4.1" data-path="../Egret/Egret 白鹭引擎参考资料.html">
            
                <a href="../Egret/Egret 白鹭引擎参考资料.html">
            
                    
                    Egret 白鹭引擎参考资料
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.2" data-path="../Egret/EGER PRO.html">
            
                <a href="../Egret/EGER PRO.html">
            
                    
                    EGER PRO
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.3" data-path="../Egret/Egret 寻路.html">
            
                <a href="../Egret/Egret 寻路.html">
            
                    
                    Egret 寻路
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">工具</li>
        
        
    
        <li class="chapter " data-level="5.1" data-path="../Tools/homebrew 使用.html">
            
                <a href="../Tools/homebrew 使用.html">
            
                    
                    homebrew 使用
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="5.2" data-path="../Tools/git 使用.html">
            
                <a href="../Tools/git 使用.html">
            
                    
                    git 使用
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">小程序</li>
        
        
    
        <li class="chapter " data-level="6.1" data-path="../MiniApp/Atom 完美支持 WePY 小程序开发.html">
            
                <a href="../MiniApp/Atom 完美支持 WePY 小程序开发.html">
            
                    
                    Atom 完美支持 WePY 小程序开发
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="6.2" data-path="../MiniApp/Atom 插件安装慢解决方案.html">
            
                <a href="../MiniApp/Atom 插件安装慢解决方案.html">
            
                    
                    Atom 插件安装慢解决方案
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">Vue</li>
        
        
    
        <li class="chapter " data-level="7.1" data-path="../Vue2/Web 前端环境搭建.html">
            
                <a href="../Vue2/Web 前端环境搭建.html">
            
                    
                    Web 前端环境搭建
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="7.2" data-path="../Vue2/Vue 项目搭建.html">
            
                <a href="../Vue2/Vue 项目搭建.html">
            
                    
                    Vue 项目搭建
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="7.3" data-path="../Vue2/初识 VueCli 3.html">
            
                <a href="../Vue2/初识 VueCli 3.html">
            
                    
                    初识 VueCli 3
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="7.4" data-path="../Vue2/使用 VueCli 3.html">
            
                <a href="../Vue2/使用 VueCli 3.html">
            
                    
                    使用 VueCli 3
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="7.5" data-path="../Vue2/VueCli 3 项目配置.html">
            
                <a href="../Vue2/VueCli 3 项目配置.html">
            
                    
                    VueCli 3 项目配置
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="7.6" data-path="../Vue3/Vue3探索.html">
            
                <a href="../Vue3/Vue3探索.html">
            
                    
                    初识 Vue3
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">微前端</li>
        
        
    
        <li class="chapter " data-level="8.1" data-path="../MicroApp/qiankun/">
            
                <a href="../MicroApp/qiankun/">
            
                    
                    qiankun
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">团队成长</li>
        
        
    
        <li class="chapter " data-level="9.1" data-path="../Team/Web前端开发规范.html">
            
                <a href="../Team/Web前端开发规范.html">
            
                    
                    开发规范
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="9.2" data-path="../Team/Web团队建设--npm私库搭建.html">
            
                <a href="../Team/Web团队建设--npm私库搭建.html">
            
                    
                    私库搭建
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="9.3" data-path="../Team/Web团队建设--自定义脚手架.html">
            
                <a href="../Team/Web团队建设--自定义脚手架.html">
            
                    
                    脚手架搭建
            
                </a>
            

            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            本书使用 GitBook 发布
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href=".." >CodePush 热更新配置及使用</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <div id="anchor-navigation-ex-navbar"><i class="fa fa-anchor"></i><ul><li><span class="title-icon "></span><a href="#codepush-&#x70ED;&#x66F4;&#x65B0;&#x914D;&#x7F6E;&#x53CA;&#x4F7F;&#x7528;"><b></b>CodePush &#x70ED;&#x66F4;&#x65B0;&#x914D;&#x7F6E;&#x53CA;&#x4F7F;&#x7528;</a></li></ul></div><a href="#codepush-&#x70ED;&#x66F4;&#x65B0;&#x914D;&#x7F6E;&#x53CA;&#x4F7F;&#x7528;" id="anchorNavigationExGoTop"><i class="fa fa-arrow-up"></i></a><h1 id="codepush-&#x70ED;&#x66F4;&#x65B0;&#x914D;&#x7F6E;&#x53CA;&#x4F7F;&#x7528;"><a name="codepush-&#x70ED;&#x66F4;&#x65B0;&#x914D;&#x7F6E;&#x53CA;&#x4F7F;&#x7528;" class="anchor-navigation-ex-anchor" href="#codepush-&#x70ED;&#x66F4;&#x65B0;&#x914D;&#x7F6E;&#x53CA;&#x4F7F;&#x7528;"><i class="fa fa-link" aria-hidden="true"></i></a>CodePush &#x70ED;&#x66F4;&#x65B0;&#x914D;&#x7F6E;&#x53CA;&#x4F7F;&#x7528;</h1>
<h3 id="&#x57FA;&#x672C;&#x4F7F;&#x7528;&#x547D;&#x4EE4;"><a name="&#x57FA;&#x672C;&#x4F7F;&#x7528;&#x547D;&#x4EE4;" class="anchor-navigation-ex-anchor" href="#&#x57FA;&#x672C;&#x4F7F;&#x7528;&#x547D;&#x4EE4;"><i class="fa fa-link" aria-hidden="true"></i></a>&#x57FA;&#x672C;&#x4F7F;&#x7528;&#x547D;&#x4EE4;</h3>
<hr>
<ol>
<li>&#x5B89;&#x88C5; <code>CodePush</code> &#xFF1A;npm install -g code-push-cli</li>
<li>&#x767B;&#x9646;&#xFF1A;code-push login</li>
<li>&#x6CE8;&#x9500;&#xFF1A;code-push logout</li>
<li>&#x6DFB;&#x52A0;&#x9879;&#x76EE;&#xFF1A;code-push app add [app&#x540D;&#x79F0;]</li>
<li>&#x5220;&#x9664;&#x9879;&#x76EE;&#xFF1A;code-push app remove [app&#x540D;&#x79F0;]</li>
<li>&#x5217;&#x51FA;&#x8D26;&#x53F7;&#x4E0B;&#x7684;&#x6240;&#x6709;&#x9879;&#x76EE;&#xFF1A;code-push app list</li>
<li><p>&#x6253;&#x5305;&#x547D;&#x4EE4;&#xFF1A;react-native bundle --platform &#x5E73;&#x53F0; --entry-file &#x542F;&#x52A8;&#x6587;&#x4EF6; --bundle-output &#x6253;&#x5305;js&#x8F93;&#x51FA;&#x6587;&#x4EF6; --assets-dest &#x8D44;&#x6E90;&#x8F93;&#x51FA;&#x76EE;&#x5F55; --dev &#x662F;&#x5426;&#x8C03;&#x8BD5;</p>
<p> &#x6CE8;&#xFF1A;</p>
<blockquote>
<p>&#x6B64;&#x5904;&#x7684; <code>--bundle-output</code> &#x548C; <code>--assets-dest</code> &#x7684;&#x8DEF;&#x5F84;&#x5EFA;&#x8BAE;&#x4F7F;&#x7528;&#x540C;&#x4E00;&#x8DEF;&#x5F84;&#xFF0C;&#x5426;&#x5219;&#x5728;&#x4F7F;&#x7528; <code>CodePush</code> &#x8FDB;&#x884C;&#x66F4;&#x65B0;&#x7248;&#x672C;&#x540E;&#x4F1A;&#x51FA;&#x73B0;&#x672C;&#x5730;&#x8D44;&#x6E90;&#x6587;&#x4EF6;&#x52A0;&#x8F7D;&#x4E0D;&#x5230;&#x7684;&#x73B0;&#x8C61;</p>
</blockquote>
</li>
<li><p>&#x53D1;&#x5E03;&#x66F4;&#x65B0;&#x547D;&#x4EE4;&#xFF1A;code-push release &lt;&#x5E94;&#x7528;&#x540D;&#x79F0;&gt; <bundles所在目录> &lt;&#x5BF9;&#x5E94;&#x7684;&#x5E94;&#x7528;&#x7248;&#x672C;&gt; --deploymentName &#x66F4;&#x65B0;&#x73AF;&#x5883; --description &#x66F4;&#x65B0;&#x63CF;&#x8FF0; --mandatory &#x662F;&#x5426;&#x5F3A;&#x5236;&#x66F4;&#x65B0;</bundles所在目录></p>
<p> &#x6CE8;&#xFF1A;</p>
<blockquote>
<ol>
<li>&#x6B64;&#x5904;&#x7684; <code>&#x5BF9;&#x5E94;&#x7684;&#x5E94;&#x7528;&#x7248;&#x672C;</code> &#x4E3A; <code>app</code> &#x5BF9;&#x5E94;&#x7684;&#x7248;&#x672C; &#x5426;&#x5219;&#x4E0D;&#x63D0;&#x793A;&#x66F4;&#x65B0;</li>
<li>&#x6B64;&#x5904;&#x7684; <code>Bundles&#x6240;&#x5728;&#x76EE;&#x5F55;</code> &#x4E3A; js &#x6253;&#x5305;&#x547D;&#x4EE4;&#x4E2D;&#x5BF9;&#x5E94;&#x7684;&#x8F93;&#x51FA;&#x76EE;&#x5F55;&#xFF0C;&#x5373;<code>--bundle-output</code> &#x540E;&#x7D27;&#x8DDF;&#x7684;&#x8DEF;&#x5F84;</li>
<li>&#x6B64;&#x5904;&#x7684; <code>deploymentName</code> &#x7684;&#x9ED8;&#x8BA4;&#x503C;&#x4E3A; <code>Staging</code> &#xFF0C;&#x82E5;&#x9700;&#x66F4;&#x65B0; <code>Staging</code> &#x7248;&#x672C;&#x65F6;&#x53EF;&#x4E0D;&#x586B;&#x5199;&#xFF0C;&#x5BF9;&#x5E94;&#x503C;&#x4E3A; <code>Staging</code> &#x6216; <code>Production</code></li>
<li>&#x6B64;&#x5904;&#x7684; <code>mandatory</code> &#x4E3A;&#x662F;&#x5426;&#x5F3A;&#x5236;&#x66F4;&#x65B0;&#x9009;&#x9879;&#xFF0C;&#x5BF9;&#x5E94;&#x503C;&#x4E3A; <code>true</code> &#x6216; <code>false</code>&#xFF0C;&#x8BBE;&#x7F6E;&#x4E3A; <code>false</code> &#x65F6;&#x7A0B;&#x5E8F;&#x4F1A;&#x5728;&#x66F4;&#x65B0;&#x540E;&#x5728;&#x4E0B;&#x6B21;&#x8FDB;&#x5165;&#x65F6;&#x663E;&#x793A;&#x65B0;&#x7248;&#x672C;&#x5185;&#x5BB9;&#xFF0C;&#x82E5;&#x8BBE;&#x7F6E;&#x4E3A; <code>true</code> &#x5219;&#x4F1A;&#x5728;&#x66F4;&#x65B0;&#x540E;&#x7ACB;&#x5373;&#x91CD;&#x542F;&#x5E94;&#x7528;&#x5E76;&#x663E;&#x793A;&#x65B0;&#x7248;&#x672C;&#x5185;&#x5BB9;</li>
</ol>
</blockquote>
</li>
</ol>
<ol>
<li><p>&#x4FEE;&#x6539;&#x66F4;&#x65B0;&#xFF1A;code-push patch <appname> <deploymentname> [--label <label>] [--description <description>] [--disabled] [--mandatory] [--rollout <rolloutpercentage>]</rolloutpercentage></description></label></deploymentname></appname></p>
<p> &#x6CE8;&#xFF1A;</p>
<blockquote>
<ol>
<li>--label, -l &#x6307;&#x5B9A;&#x6807;&#x7B7E;&#x7248;&#x672C;&#x66F4;&#x65B0;&#xFF0C;&#x9ED8;&#x8BA4;&#x6700;&#x65B0;&#x7248;&#x672C; [string] [&#x9ED8;&#x8BA4;&#x503C;: null]</li>
<li>--description, --des &#x63CF;&#x8FF0; [string] [&#x9ED8;&#x8BA4;&#x503C;: null]</li>
<li>--disabled, -x &#x662F;&#x5426;&#x7981;&#x7528;&#x8BE5;&#x66F4;&#x65B0; [boolean] [&#x9ED8;&#x8BA4;&#x503C;: null]</li>
<li>--mandatory, -m &#x662F;&#x5426;&#x5F3A;&#x5236;&#x66F4;&#x65B0; [boolean] [&#x9ED8;&#x8BA4;&#x503C;: null]</li>
<li>--rollout, -r &#x6B64;&#x66F4;&#x65B0;&#x63A8;&#x9001;&#x7528;&#x6237;&#x7684;&#x767E;&#x5206;&#x6BD4;&#xFF0C;&#x6B64;&#x503C;&#x4EC5;&#x53EF;&#x4EE5;&#x4ECE;&#x5148;&#x524D;&#x7684;&#x503C;&#x589E;&#x52A0;&#x3002; [string] [&#x9ED8;&#x8BA4;&#x503C;: null]</li>
</ol>
</blockquote>
</li>
<li><p>&#x56DE;&#x6EDA;&#x66F4;&#x65B0;&#xFF1A;code-push rollback <appname> <deploymentname> [--targetRelease <releaselabel>]</releaselabel></deploymentname></appname></p>
<p>&#x6CE8;&#xFF1A;</p>
<blockquote>
<p>--targetRelease, -r &#x6307;&#x5B9A;&#x56DE;&#x5F52;&#x5230;&#x54EA;&#x4E2A;&#x6807;&#x7B7E;&#xFF0C;&#x9ED8;&#x8BA4;&#x662F;&#x56DE;&#x6EDA;&#x5230;&#x4E0A;&#x4E00;&#x4E2A;&#x66F4;&#x65B0; [string] [&#x9ED8;&#x8BA4;&#x503C;: null]</p>
</blockquote>
</li>
<li><p>&#x67E5;&#x770B;&#x5386;&#x53F2;&#x7248;&#x672C;&#xFF1A;code-push deployment history <appname> <deploymentnmae> (Production &#x6216;&#x8005; Staging)</deploymentnmae></appname></p>
</li>
<li><p>&#x6E05;&#x9664;&#x5386;&#x53F2;&#x7248;&#x672C;&#xFF1A;code-push deployment clear <appname> <deploymentname> </deploymentname></appname></p>
</li>
</ol>
<h3 id="&#x96C6;&#x6210;&#x914D;&#x7F6E;&#x4FE1;&#x606F;&#xFF08;android&#xFF09;"><a name="&#x96C6;&#x6210;&#x914D;&#x7F6E;&#x4FE1;&#x606F;&#xFF08;android&#xFF09;" class="anchor-navigation-ex-anchor" href="#&#x96C6;&#x6210;&#x914D;&#x7F6E;&#x4FE1;&#x606F;&#xFF08;android&#xFF09;"><i class="fa fa-link" aria-hidden="true"></i></a>&#x96C6;&#x6210;&#x914D;&#x7F6E;&#x4FE1;&#x606F;&#xFF08;android&#xFF09;</h3>
<hr>
<h4 id="js-&#x90E8;&#x5206;&#x914D;&#x7F6E;"><a name="js-&#x90E8;&#x5206;&#x914D;&#x7F6E;" class="anchor-navigation-ex-anchor" href="#js-&#x90E8;&#x5206;&#x914D;&#x7F6E;"><i class="fa fa-link" aria-hidden="true"></i></a>Js &#x90E8;&#x5206;&#x914D;&#x7F6E;</h4>
<blockquote>
<p>&#x66F4;&#x65B0;&#x6A21;&#x5F0F;&#x5206;&#x4E3A;&#x81EA;&#x52A8;&#x6A21;&#x5F0F;&#x4E0E;&#x624B;&#x52A8;&#x6A21;&#x5F0F;&#x4E24;&#x79CD;</p>
</blockquote>
<ul>
<li>&#x81EA;&#x52A8;&#x6A21;&#x5F0F; <code>CodePush.sync()</code> </li>
</ul>
<p><code>CodePush.sync()</code> &#x51FD;&#x6570;&#x4E3A; <code>sync(options?: SyncOptions, syncStatusChangedCallback?: SyncStatusChangedCallback, downloadProgressCallback?: DowloadProgressCallback)</code></p>
<ol>
<li><code>SyncOptions</code> &#x5185;&#x5305;&#x542B;&#x6709; <code>deploymentKey</code>&#x3001;<code>installMode</code>&#x3001;<code>mandatoryInstallMode</code>&#x3001;<code>minimumBackgroundDuration</code>&#x3001;<code>updateDialog</code> &#x5C5E;&#x6027;&#xFF0C;&#x6B64;&#x5904;&#x5C5E;&#x6027;&#x7684;&#x5BF9;&#x5E94;&#x4ECB;&#x7ECD;&#x53EF;&#x89C1;&#x5176;&#x6E90;&#x7801;&#x6CE8;&#x91CA;&#x90E8;&#x5206;&#xFF0C;&#x5F88;&#x8BE6;&#x7EC6;</li>
<li><code>SyncStatusChangedCallback</code> &#x4E3A;&#x66F4;&#x65B0;&#x7684;&#x72B6;&#x6001;&#x56DE;&#x8C03;&#x65B9;&#x6CD5;&#xFF0C;&#x53EF;&#x901A;&#x8FC7;&#x6DFB;&#x52A0;&#x6B64;&#x65B9;&#x6CD5;&#x6765;&#x76D1;&#x542C;&#x66F4;&#x65B0;&#x7684;&#x72B6;&#x6001;&#xFF0C;&#x5982;&#x68C0;&#x67E5;&#x5230;&#x66F4;&#x65B0;&#x3001;&#x66F4;&#x65B0;&#x5B8C;&#x6210;&#x3001;&#x66F4;&#x65B0;&#x5931;&#x8D25;&#x7B49;&#x72B6;&#x6001;&#xFF0C;&#x5BF9;&#x5E94;&#x4EE3;&#x7801;&#x4E3A;</li>
</ol>
<pre><code>codePushStatusDidChange(syncStatus) {
        switch(syncStatus) {
            case CodePush.SyncStatus.CHECKING_FOR_UPDATE:
                console.log(&quot;&#x66F4;&#x65B0;===&#x68C0;&#x67E5;&#x66F4;&#x65B0;&#x4E2D;&quot;);
                break;
            case CodePush.SyncStatus.DOWNLOADING_PACKAGE:
                console.log(&quot;&#x66F4;&#x65B0;===&#x4E0B;&#x8F7D;&#x66F4;&#x65B0;&#x5305;&quot;);
                break;
            case CodePush.SyncStatus.AWAITING_USER_ACTION:
                console.log(&quot;&#x66F4;&#x65B0;===&#x68C0;&#x67E5;&#x5230;&#x65B0;&#x7248;&#x672C;&#xFF0C;&#x7B49;&#x5F85;&#x7528;&#x6237;&#x64CD;&#x4F5C;&quot;);
                break;
            case CodePush.SyncStatus.INSTALLING_UPDATE:
                console.log(&quot;&#x66F4;&#x65B0;===&#x6B63;&#x5728;&#x5B89;&#x88C5;&#x66F4;&#x65B0;&quot;);
                break;
            case CodePush.SyncStatus.UP_TO_DATE:
                console.log(&quot;&#x66F4;&#x65B0;===&#x5DF2;&#x662F;&#x6700;&#x65B0;&#x7248;&#x672C;&quot;);
                break;
            case CodePush.SyncStatus.UPDATE_IGNORED:
                console.log(&quot;&#x66F4;&#x65B0;===&#x7528;&#x6237;&#x53D6;&#x6D88;&#x66F4;&#x65B0;&quot;);
                break;
            case CodePush.SyncStatus.UPDATE_INSTALLED:
                console.log(&quot;&#x66F4;&#x65B0;===&#x5DF2;&#x5B89;&#x88C5;&#x66F4;&#x65B0;&#xFF0C;&#x5C06;&#x5728;&#x91CD;&#x65B0;&#x542F;&#x52A8;&#x65F6;&#x5E94;&#x7528;&quot;);
                break;
            case CodePush.SyncStatus.UNKNOWN_ERROR:
                console.log(&quot;&#x66F4;&#x65B0;===&#x53D1;&#x751F;&#x4E86;&#x4E00;&#x4E2A;&#x672A;&#x77E5;&#x9519;&#x8BEF;&quot;);
                break;
        }
    }
</code></pre><ol>
<li><code>DowloadProgressCallback</code> &#x4E3A;&#x66F4;&#x65B0;&#x4E0B;&#x8F7D;&#x8FDB;&#x5EA6;&#x7684;&#x56DE;&#x8C03;&#x65B9;&#x6CD5;&#xFF0C;&#x53EF;&#x901A;&#x8FC7;&#x6DFB;&#x52A0;&#x6B64;&#x65B9;&#x6CD5;&#x76D1;&#x542C;&#x4E0B;&#x8F7D;&#x7684;&#x8FDB;&#x5EA6;&#xFF0C; &#x5176;&#x5C5E;&#x6027;&#x503C;&#x4E3A; <code>totalBytes</code> &#x548C; <code>totalBytes</code>&#xFF0C; &#x5206;&#x522B;&#x4E3A;&#x66F4;&#x65B0;&#x5305;&#x7684;&#x603B;&#x5927;&#x5C0F;&#x4E0E;&#x5F53;&#x5148;&#x4E0B;&#x8F7D;&#x8FDB;&#x5EA6;</li>
</ol>
<p>&#x5177;&#x4F53;&#x4F7F;&#x7528;&#x793A;&#x4F8B;&#xFF1A;</p>
<pre><code>CodePush.sync(
        { 
            installMode: CodePush.InstallMode.ON_NEXT_RESTART,
            updateDialog: {
                appendReleaseDescription: true,
                descriptionPrefix:&apos;&#x66F4;&#x65B0;&#x5185;&#x5BB9;&#xFF1A;\n&apos;,
                title:&apos;&#x66F4;&#x65B0;&apos;,
                mandatoryUpdateMessage:&apos; &apos;,
                mandatoryContinueButtonLabel:&apos;&#x66F4;&#x65B0;&apos;,
            },
        },
        this.codePushStatusDidChange.bind(this),
        this.codePushDownloadDidProgress.bind(this)
    );

    // &#x4E5F;&#x53EF;&#x4EE5;&#x76F4;&#x63A5;&#x4F7F;&#x7528; CodePush.sync() &#x65B9;&#x6CD5;&#x8FDB;&#x884C;&#x66F4;&#x65B0;
</code></pre><p>&#x6CE8;&#xFF1A;</p>
<blockquote>
<p>&#x5728;&#x7A0B;&#x5E8F;&#x7684;&#x5165;&#x53E3;&#x5904;&#x9700;&#x6DFB;&#x52A0;&#x4EE5;&#x4E0B;&#x4EE3;&#x7801;</p>
</blockquote>
<pre><code>let codePushOptions = { checkFrequency: CodePush.CheckFrequency.MANUAL };
&lt;&#x586B;&#x5199;&#x8BE5;&#x7C7B;&#x540D;&gt; = CodePush(codePushOptions)(&lt;&#x586B;&#x5199;&#x8BE5;&#x7C7B;&#x540D;&gt;);

AppRegistry.registerComponent(&apos;&lt;&#x586B;&#x5199;&#x6B64;&#x5904;&#x4E3A;&#x521B;&#x5EFA;&#x65F6;&#x7684;&#x5E94;&#x7528;&#x540D;&gt;&apos;, () =&gt; &lt;&#x586B;&#x5199;&#x8BE5;&#x7C7B;&#x540D;&gt;);
</code></pre><blockquote>
<p>&#x624B;&#x52A8;&#x6A21;&#x5F0F;&#x6682;&#x65F6;&#x672A;&#x7814;&#x7A76; &#x5177;&#x4F53; API &#x53EF;&#x53C2;&#x89C1;&#x5B98;&#x65B9;&#x6587;&#x6863;</p>
</blockquote>
<h4 id="&#x539F;&#x751F;&#x90E8;&#x5206;&#x8BBE;&#x7F6E;"><a name="&#x539F;&#x751F;&#x90E8;&#x5206;&#x8BBE;&#x7F6E;" class="anchor-navigation-ex-anchor" href="#&#x539F;&#x751F;&#x90E8;&#x5206;&#x8BBE;&#x7F6E;"><i class="fa fa-link" aria-hidden="true"></i></a>&#x539F;&#x751F;&#x90E8;&#x5206;&#x8BBE;&#x7F6E;</h4>
<ul>
<li>build.gradle</li>
</ul>
<blockquote>
<p>&#x6B64;&#x5904;&#x5206;&#x4E24;&#x79CD;&#x60C5;&#x51B5;&#xFF0C;&#x4E00;&#x79CD;&#x4E3A;&#x4E0D;&#x9700;&#x8981;&#x6539;&#x52A8; <code>CodePush</code> &#x539F;&#x751F;&#x4EE3;&#x7801;&#xFF1B; &#x53E6;&#x4E00;&#x79CD;&#x4E3A;&#x9700;&#x8981;&#x6539;&#x52A8; <code>CodePush</code> &#x7684;&#x539F;&#x751F;&#x4EE3;&#x7801;&#xFF0C;&#x6B64;&#x65F6;&#x5982;&#x679C;&#x8BE5;&#x9879;&#x76EE;&#x662F;&#x63D2;&#x4EF6;&#x7C7B;&#x578B;&#x7684;&#x8BDD;&#x8FD8;&#x9700;&#x8981;&#x5C06;&#x6539;&#x52A8;&#x540E;&#x7684; <code>CodePush</code> &#x7684;&#x4EE3;&#x7801;&#x4E0A;&#x4F20;&#x5230;&#x79C1;&#x5E93;&#xFF0C;&#x5426;&#x5219;&#x901A;&#x8FC7;&#x8FDC;&#x7A0B;&#x5E93;&#x7684;&#x5F15;&#x7528;&#x65B9;&#x5F0F;&#x65E0;&#x6CD5;&#x5F15;&#x7528;&#x5230;&#x8BE5;&#x90E8;&#x5206;&#x4EE3;&#x7801;&#xFF0C;&#x82E5;&#x4E0D;&#x4F7F;&#x7528;&#x8FDC;&#x7A0B;&#x5E93;&#x5F15;&#x7528;&#x7684;&#x8BDD;&#x53EA;&#x9700;&#x62F7;&#x8D1D;&#x4EE3;&#x7801;&#x5373;&#x53EF;&#xFF0C;&#x6B64;&#x5904;&#x9700;&#x8981;&#x6CE8;&#x610F;&#x7684;&#x662F;&#x5176;&#x6E90;&#x7801;&#x5185; <code>codepush.gradle</code> &#x6587;&#x4EF6;&#x5FC5;&#x987B;&#x8C03;&#x7528;&#xFF0C;&#x5426;&#x5219;&#x6253;&#x5305;&#x540E; <code>CodePush</code> &#x4F1A;&#x56E0;&#x67E5;&#x627E;&#x4E0D;&#x5230; <code>CODE_PUSH_APK_BUILD_TIME</code> &#x6B64;&#x5B57;&#x6BB5;&#x800C;&#x5BFC;&#x81F4;&#x7A0B;&#x5E8F;&#x505C;&#x6B62;&#x8FD0;&#x884C;&#xFF1B;&#x82E5;&#x662F;&#x8BE5;&#x7A0B;&#x5E8F;&#x53EA;&#x662F;&#x4E00;&#x4E2A;&#x666E;&#x901A;&#x7684;&#x9879;&#x76EE;&#x7684;&#x8BDD;&#x5219;&#x6CA1;&#x6709;&#x8FD9;&#x4E9B;&#x987E;&#x8651;&#xFF0C;&#x5C3D;&#x7BA1;&#x6539;&#x5C31;&#x53EF;&#x4EE5;&#x4E86;</p>
<p>&#x6B64;&#x5904;&#x6307;&#x7684;&#x662F; <code>app</code> &#x4E0B;&#x9762;&#x7684; <code>build.gradle</code> </p>
</blockquote>
<p>&#x6DFB;&#x52A0;&#x914D;&#x7F6E;&#x4EE3;&#x7801;&#xFF1A;</p>
<pre><code>apply from: &quot;../../node_modules/react-native-code-push/android/codepush.gradle&quot;

Properties properties = new Properties()
properties.load(project.rootProject.file(&apos;local.properties&apos;).newDataInputStream())

android {
    ...

    buildTypes {
        // &#x6B64;&#x5904;&#x9700;&#x6CE8;&#x610F;CodePush&#x4E0D;&#x652F;&#x6301;&#x5728;DeBug&#x6A21;&#x5F0F;&#x4E0B;&#x4F7F;&#x7528;
        releaseStaging {
            ...
            buildConfigField &quot;String&quot;, &quot;CODEPUSH_KEY&quot;, &apos;&quot;&apos;+properties.getProperty(&quot;code_push_key_staging&quot;)+&apos;&quot;&apos;
            ...
        }

        releaseProduction {
            ...
            buildConfigField &quot;String&quot;, &quot;CODEPUSH_KEY&quot;, &apos;&quot;&apos;+properties.getProperty(&quot;code_push_key_production&quot;)+&apos;&quot;&apos;
            ...
        }
    }

}
</code></pre><ul>
<li>local.properties</li>
</ul>
<p>&#x9879;&#x76EE;&#x6700;&#x5916;&#x5C42;&#x8BE5;&#x6587;&#x4EF6;&#x4E0B;&#x6DFB;&#x52A0;&#x4E00;&#x4E0B;&#x4E24;&#x4E2A;&#x5C5E;&#x6027;&#x503C;</p>
<pre><code>code_push_key_production=&#x8BE5;&#x5E94;&#x7528;&#x7684; production &#x7248;&#x672C;&#x7684;Key
code_push_key_staging=&#x8BE5;&#x5E94;&#x7528;&#x7684; staging &#x7248;&#x672C;&#x7684;Key
</code></pre><ul>
<li>MainApplication</li>
</ul>
<pre><code>
public class MainApplication extends Application implements ReactApplication {


    private static final String code_push_key_production=&quot;zYDSBi96YCB7fISlK9wJTanpbcnFd4eb246d-c057-4aa7-8dfd-a6f32494bd71&quot;;
    private static final String code_push_key_staging=&quot;g5e_Ttrw183uWyZRuVP4VUzAXlTvd4eb246d-c057-4aa7-8dfd-a6f32494bd71&quot;;
    // &#x8FD9;&#x4E24;&#x4E2A;&#x503C;&#x4E5F;&#x53EF;&#x4EE5;&#x901A;&#x8FC7;&#x8BFB;&#x53D6; local.properties &#x6587;&#x4EF6;&#x83B7;&#x5F97;

    private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {

        @Override
        protected String getJSBundleFile() {
            return CodePush.getJSBundleFile();
        }

        @Override
        public boolean getUseDeveloperSupport() {
            return BuildConfig.DEBUG;
        }

        @Override
        protected List&lt;ReactPackage&gt; getPackages() {
            return Arrays.&lt;ReactPackage&gt;asList(
                    new MainReactPackage(),
                    new CodePush(code_push_key_production, getApplicationContext())
            );
        }
    };

    @Override
    public ReactNativeHost getReactNativeHost() {
        return mReactNativeHost;
    }

    @Override
    public void onCreate() {
        super.onCreate();
        SoLoader.init(this, /* native exopackage */ false);
    }

}
</code></pre><blockquote>
<p>&#x8FD8;&#x6709;&#x4E00;&#x79CD;&#x60C5;&#x51B5;&#xFF0C;&#x90A3;&#x5C31;&#x662F;&#x4E0D;&#x5B9A;&#x4E49; <code>Application</code> &#x7684;&#x60C5;&#x51B5;&#x4E0B;&#x4F7F;&#x7528;&#xFF0C;&#x6B64;&#x65F6;&#x5219;&#x53EF;&#x4EE5;&#x5728; <code>MainActivity</code> &#x4E2D;&#x5982;&#x4E0B;&#x914D;&#x7F6E;&#xFF1A;</p>
</blockquote>
<pre><code>public class MainActivity extends Activity implements DefaultHardwareBackBtnHandler {

    ...

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        CodePush codePush = new CodePush(code_push_key_production,this);
        mReactRootView = new ReactRootView(this);
        mReactInstanceManager = ReactInstanceManager.builder()
                .setApplication(getApplication())
                .setBundleAssetName(&quot;index.android.bundle&quot;)

                ...

                .setJSBundleFile(codePush.getJSBundleFile(&quot;index.android.bundle&quot;))
                .addPackage(codePush)

                ...

                .setUseDeveloperSupport(true)
                .setInitialLifecycleState(LifecycleState.RESUMED)
                .build();


        mReactRootView.startReactApplication(mReactInstanceManager, &quot;&lt;&#x5BF9;&#x5E94;RN&#x4E2D;&#x6CE8;&#x518C;&#x7684;&#x540D;&#x5B57;&gt;&quot;, null);
        setContentView(mReactRootView);

        mReactInstanceManager.addReactInstanceEventListener(new ReactInstanceManager.ReactInstanceEventListener() {
            @Override
            public void onReactContextInitialized(ReactContext context) {
                reactContext = context;
            }
        });
    }

    ...

}
</code></pre><p>&#x81F3;&#x6B64;&#x5927;&#x529F;&#x544A;&#x6210;&#x3002;</p>
<footer class="page-footer"><span class="copyright">Copyright &amp; copy zengqing.top 2023 all right reserved&#xFF0C;powered by Gitbook</span><span class="footer-modification">&#x8BE5;&#x6587;&#x4EF6;&#x66F4;&#x65B0;&#x4E8E;&#xFF1A;
2023-03-25 21:11:04
</span></footer>
                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="../Android/Android UI美化之 shape的使用及其属性总结.html" class="navigation navigation-prev " aria-label="Previous page: Android UI美化之 shape的使用及其属性总结">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="已有Android工程 集成React Native.html" class="navigation navigation-next " aria-label="Next page: 已有Android工程 集成React Native">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"CodePush 热更新配置及使用","level":"3.1","depth":1,"next":{"title":"已有Android工程 集成React Native","level":"3.2","depth":1,"path":"ReactNative/已有Android工程 集成React Native.md","ref":"./ReactNative/已有Android工程 集成React Native.md","articles":[]},"previous":{"title":"Android UI美化之 shape的使用及其属性总结","level":"2.2","depth":1,"path":"Android/Android UI美化之 shape的使用及其属性总结.md","ref":"./Android/Android UI美化之 shape的使用及其属性总结.md","articles":[]},"dir":"ltr"},"config":{"plugins":["expandable-chapters","code","pageview-count","chapter-fold","expandable-chapters-small","tbfed-pagefooter","hide-element","ancre-navigation"],"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"tbfed-pagefooter":{"copyright":"Copyright & copy zengqing.top 2023","modify_label":"该文件更新于：","modify_format":"YYYY-MM-DD HH:mm:ss"},"chapter-fold":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"code":{"copyButtons":true},"hide-element":{"elements":[".gitbook-link"]},"fontsettings":{"theme":"white","family":"sans","size":2},"highlight":{},"pageview-count":{},"ancre-navigation":{"showLevel":true,"associatedWithSummary":true,"mode":"float","printLog":false,"multipleH1":true,"float":{"showLevelIcon":false,"level1Icon":"","level2Icon":"","level3Icon":""},"pageTop":{"showLevelIcon":false,"level1Icon":"","level2Icon":"","level3Icon":""}},"expandable-chapters-small":{},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false},"expandable-chapters":{}},"theme":"default","author":"XiaoChen","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"《前端学习笔记》","language":"zh-hans","gitbook":"*","description":"个人学习笔记，记录学习过程中的点点滴滴"},"file":{"path":"ReactNative/CodePush 热更新配置及使用.md","mtime":"2023-03-25T13:11:04.059Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2023-03-26T04:06:26.355Z"},"basePath":"..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../gitbook/gitbook.js"></script>
    <script src="../gitbook/theme.js"></script>
    
        
        <script src="../gitbook/gitbook-plugin-expandable-chapters/expandable-chapters.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-code/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-pageview-count/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-chapter-fold/chapter-fold.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-expandable-chapters-small/expandable-chapters-small.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-hide-element/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

